package com.example.beryl.http;
import com.example.beryl.entity.Action;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Android 系统网络方法
 */
public class Net_userData {
    private ArrayList<String> arrayList = new ArrayList<String>();
    private ArrayList<String> brrayList = new ArrayList<String>();
    private ArrayList<String> crrayList = new ArrayList<String>();
    //private static String URL ="SystemPage.asmx";//服务器地址
    private static String URL ="SystemPage.asmx";//调试地址
    private Net_method soap2 = new Net_method();

   public List<String> User_CommonMethod(String what, String para)
   {
       List<String> list = new ArrayList<>();
       try
       {
         switch (what)
         {
             case Action.action.Login:
                 list =getAllInfo(para);
                 break;
             case Action.action.GetPerson:
                 list= getPR(para);
                 break;
             case Action.action.GetEM:
                 list= getEQ(para);
                 break;
         }
       }catch (RuntimeException e)
       {
           e.getMessage();
       }
       return list;
   }

    /**
     * arrayList: 参数名字
     * brrayList: 参数值
     * crrayList： 返回结果
     * @param User
     * @return
     */
    public List<String> getAllInfo(String User) {
       // List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
        ArrayList<String> list = new ArrayList<String>();
        arrayList.clear();
        brrayList.clear();
        crrayList.clear();
        arrayList.add("User");
        brrayList.add(User);
        try
        {
            crrayList = soap2.SummitData("SelectAllCargoInfor", arrayList, brrayList,URL);
            if (crrayList == null)
            {
                list.add("1");
                return list;
            }
            else
            {
                list = crrayList;
            }
        }
        catch (RuntimeException e)
        {
            return null;
        }
        return list;
    }

    /**
     * List对象为null时候需要把对象销毁
     * @param User
     * @return
     */
    public String getUserRole(String User)
    {
        ArrayList<String> list = new ArrayList<String>();
        arrayList.clear();
        brrayList.clear();
       // crrayList.clear();
        arrayList.add("User");
        brrayList.add(User);
        String role = "";
        try
        {
          //String soapObject = soap2.calculate("SelectAllCargoInfor",arrayList,brrayList);
            crrayList = soap2.SummitData("SelectAllCargoInfor", arrayList, brrayList,URL);
            if (crrayList == null)
            {
                //对象销毁
                crrayList.removeIf(Objects::isNull);
            }
            else
            {
                list = crrayList;
                role = list.get(0).toString();

            }
        }catch (Exception e)
        {
           System.out.println(e);
        }
        return role;
    }

    /**
     * 检查网络通讯
     * @return
     */
    public List<String> CheckNetWork()
    {
        arrayList.clear();
        brrayList.clear();
        arrayList.add("Check");
        brrayList.add("test");
        crrayList = soap2.SummitData("HelloWorld",arrayList,brrayList,URL);
        return crrayList;
        //return crrayList.get(0).toString();
    }

    //查找人员
    public List<String> getPR(String Pr)
    {
        ArrayList<String> list = new ArrayList<String>();
        arrayList.clear();
        brrayList.clear();
        arrayList.add("Pr");
        brrayList.add(Pr);
        try
        {
            crrayList = soap2.SummitData("selectgetPr", arrayList, brrayList,URL);
            if (crrayList == null)
            {
                //对象销毁
                crrayList.removeIf(Objects::isNull);
                return list;
            }
            else
            {
                list = crrayList;
            }
        }
        catch (Exception e)
        {
            return null;
        }
        return list;
    }

    //查找设备
    public List<String> getEQ(String eq)
    {
        ArrayList<String> list = new ArrayList<String>();
        arrayList.clear();
        brrayList.clear();
        arrayList.add("EQ");
        brrayList.add(eq);
        try
        {
            crrayList = soap2.SummitData("selectgetEQ", arrayList, brrayList,URL);
            if (crrayList == null)
            {
                //对象销毁
                crrayList.removeIf(Objects::isNull);
                return list;
            }
            else
            {
                list = crrayList;
            }
        }
        catch (Exception e)
        {
            return null;
        }
        return list;
    }

    public List<String> UpdateExcept(String json)
    {
        ArrayList<String> list = new ArrayList<String>();
        arrayList.clear();
        brrayList.clear();
        arrayList.add("json");
        brrayList.add(json);
        try
        {
            crrayList = soap2.SummitData("UpdateExcept", arrayList, brrayList,URL);
            if (crrayList == null)
            {
                //对象销毁
                crrayList.removeIf(Objects::isNull);
                return list;
            }
            else
            {
                list = crrayList;
            }
        }
        catch (Exception e)
        {
            return null;
        }
        return list;
    }
}
